<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="commontaglib"%>
<%
	String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="<%=path%>/css/common.css" type="text/css" />
<link rel="stylesheet" href="<%=path%>/css/innerstyle.css"
	type="text/css" />
<link rel="stylesheet" type="text/css" media="screen"
	href="<%=path%>/css/ui-lightness/jquery-ui-1.8.23.custom.css" />

<link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css"
	type="text/css">
<link rel="stylesheet" href="<%=path%>/css/zTreeStyle/demo.css"
	type="text/css">
<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/js/jquery-ui-1.8.23.custom.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/js/jquery.ztree.all-3.4.min.js"></script>
<script>
	
	$(function() {		 
		$("#but1").button();
        $( "#datepicker" ).datepicker($.datepicker.regional[ "zh-CN" ]);   
        $( "#dialog-confirm" ).dialog({
            autoOpen: false,            
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					document.form1.action="<%=path%>/cxtj/saveXtxxInfo.action";
					document.form1.method="post";
					document.form1.submit();
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});
		 
		
		$( "#jsrlist" ).dialog({
		    autoOpen: false,
		    modal: true
		   });
		
	});
	
	function tj(){
       // j$( "#dialog-confirm" ).dialog( "open" );
	   document.form1.action="<%=path%>/cxtj/saveXtxxInfo.action";
					document.form1.method="post";
					document.form1.submit();
	  return false;
	}
	
	
	function showjsrlist(){
	//alert("aa");
	  $( "#jsrname" )			
			.click(function() {
			
			$("#but2").button(); 
            $("#but3").button();
		    old_data();
            new_data();	
			
			$( "#jsrlist" ).dialog("open");
			
			$( "#jsrlist" ).dialog({
			resizable: false,
			height: 400,
		    width: 300,
			modal: true,
			buttons: {
				"确认": function() {
				
				var jsrname="";
				var jsr="";
			     var treeObj2 = $.fn.zTree.getZTreeObj("treeDemo2");
			     
			var nodes = treeObj2.getNodes();
			
			for	(var i=0;i<nodes.length;i++)
				{
					if(i==0)
					{ 
						jsrname=nodes[i].name;
						jsr+=nodes[i].id;
					}
					else
					{
						jsrname+=","+nodes[i].name;
						jsr+=","+nodes[i].id;
					}
				}
				//alert(jsr);
				//alert(jsrname);
				$( "#jsrname").val(jsrname); 
				$( "#jsr").val(jsr); 
				$( this ).dialog( "close" );
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}	
		  
		 });
	  });
	}
	
	function old_data(){
		$.ajax({
             type: "post",
             dataType:'text',
             //dataType: "json",//返回json格式的数据
             url: "<%=path%>/jydz/findjsdw.action",
             success: function(data){
                 var zNodes = data;                 
                 $.fn.zTree.init($("#treeDemo1"), setting, eval('(' + zNodes + ')')); 
                }  
              });
		}
		
		function new_data(){
		$.ajax({
             type: "post",
             dataType:'text',             
             url: "<%=path%>/jydz/findRejsdw.action",
             success: function(data){
                 var zNodes = data;
                 $.fn.zTree.init($("#treeDemo2"), setting, eval('(' + zNodes + ')')); 
                }  
              });
		}
		
		var setting = {
			view: {
				selectedMulti: false
			},
			check: {
				enable: true
			},
			edit: {
				enable: false,
				showRemoveBtn: false,
				showRenameBtn: false
			},
			  data: {
			simpleData: {
				enable:true,
				idKey: "jiesdwbm",
				pIdKey: "pid",
				rootPId: ""
			}
		},
			callback: {			    
				beforeDrag: false,
				beforeDrop: false//,
				//beforeClick: beforeClick
			
		}};
		


		function beforeDrag(treeId, treeNodes) {
			for (var i=0,l=treeNodes.length; i<l; i++) {
			    alert(treeNodes[i].pId);
				if (treeNodes[i].drag === false) {
					return false;
				}
			}
			return true;
		}
		function beforeDrop(treeId, treeNodes, targetNode, moveType) {
		    //alert(treeNodes[0].name);
			return targetNode ? targetNode.drop !== false : true;
		}
		
		function chickDrop(treeID,type)
		{		
			var treeObj = $.fn.zTree.getZTreeObj(treeID);		
			var sNodes = treeObj.getSelectedNodes();       
		    var tId = sNodes[0].tId;		   
	        var node = treeObj.getNodeByTId(tId);  
	         
			for (var i=0, l=sNodes.length; i < l; i++) 
			{				
				treeObj.removeNode(sNodes[i]);
			}
			if(type=='1')
			{	
				save(sNodes);       	
			}
			else
			{
				remove(sNodes); 						
			}
		}
		
		function save(zNodes)
		{	
			var treeObj2 = $.fn.zTree.getZTreeObj("treeDemo2");
			treeObj2.addNodes (null,zNodes);		
		}
		
		function remove(zNodes)
		{
		 	var treeObj1 = $.fn.zTree.getZTreeObj("treeDemo1");
			treeObj1.addNodes (null,zNodes);
		}
		
		function beforeClick(treeId, treeNode) {
			if (treeNode.isParent) {
				return false;
			} else {
				//alert("这个 Demo 是用来测试 展开 / 折叠 的...\n\n去点击父节点吧... ");
				return true;
			}
		}
		
	
	</script>
</head>

<body>
	<div id="best1">
		<h2>
			<span>发送消息</span>
		</h2>
		<form name="form1">
			<table id="list_search" cellpadding="0" cellspacing="0" border="0"
				class="content_gridview">
				<tr>
					<td>

						<table cellpadding="0" cellspacing="0" border="0"
							class="content_gridview">
							<tr>
								<td><a onClick="showjsrlist();">接收人:</a></td>
								<td align="left"><textarea cols="90" rows="6" id="jsrname"
										class="textarea" name="bean.BB" readonly="readonly"
										></textarea> <input type="hidden"
									id="jsr" cols="90" rows="6" name="bean.AA">
								</textarea></td>
							</tr>
							<tr>
								<td>信息内容:</td>
								<td><textarea cols="90" rows="10" class="textarea"
										name="bean.BB"></textarea></td>
							</tr>


						</table></td>
				</tr>

				<tr>
					<td colspan="4" align="center"><input id="but1" type="button"
						name="" value="发送" onClick="tj();" />
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
				</tr>
			</table>
		</form>
	</div>
	<div id="jsrlist" title="接收人">
		<div class="content_wrap">

			<div class="zTreeDemoBackground left">

				<ul id="treeDemo1" class="ztree"></ul>
			</div>

			<div class="center"  style="display:none; width:auto;">
				<input type="button" id="but2" value=">"
					onClick="chickDrop('treeDemo1','1');" /> <br> <input
					type="button" id="but3" value="<" onClick=" chickDrop('treeDemo2','2');"/>
			</div>

			<div class="right" style="display:none; width:auto;" >

				<ul id="treeDemo2" class="ztree" ></ul>
			</div>

		</div>

	</div>



	<div id="dialog-confirm" title="是否确认发送？"></div>
</body>
</html>
